import { WelfareItem } from "./WelfareItem";
import { ItemConfig } from "../../../resource/ItemConfig";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { EProp } from "../../../../../Message/Public/EProp";
import { EBind } from "../../../../../Message/Public/EBind";
import { ItemData } from "../../../resource/info/ItemData";
import { ShopConfig } from "../../../resource/ShopConfig";
import { Language } from "../../../../../extend/language/Language";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GNumericStepper } from "../../../../../com/mui/controls/GNumericStepper";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
import { OfflineExpPropModule } from "../../../../../modules/OfflineExpPropModule";
import { Cache } from "../../../cache/Cache";
import { ColorConfig } from "../../../resource/ColorConfig";
import { QuickBuyWindow } from "../../common/QuickBuyWindow";
import { EExpType } from "../../../../../Message/Game/EExpType";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { ShopItemInfo } from "../../../resource/info/ShopItemInfo";
import { _EExpTypeDirect } from "../../../../../EExpType/_EExpTypeDirect";
import { _timeNum } from "../../../../../this/_timeNum";
import { _EExpTypeTwice } from "../../../../../EExpType/_EExpTypeTwice";
import { _EExpTypeTriple } from "../../../../../EExpType/_EExpTypeTriple";
import { _expType } from "../../../../../this/_expType";
type int = number;
//class WelOffLineExpItem
    
    export  class WelOffLineExpItem extends WelfareItem
    {
        constructor()
        {
            super();
            var loc1=ItemConfig.instance.getItemByType(ECategory._ECategoryProp, EProp._EPropOfflineAddExperience, EBind._EBindNo, 200);
            this._itemData1 = new ItemData(loc1.item.code);
            loc1 = ItemConfig.instance.getItemByType(ECategory._ECategoryProp, EProp._EPropOfflineAddExperience, EBind._EBindNo, 300);
            this._itemData2 = new ItemData(loc1.item.code);
            this._shopItem1 = ShopConfig.instance.getGoldItemByType(ECategory._ECategoryProp, EProp._EPropOfflineAddExperience, 200);
            this._shopItem2 = ShopConfig.instance.getGoldItemByType(ECategory._ECategoryProp, EProp._EPropOfflineAddExperience, 300);
            return;
        }

        protected /* override */ initUI(): void
        {
            super.initUI();
            _titleTxt.text = Language.getString(20607);
            _titleTxt2.text = Language.getString(20600) + "：0" + Language.getString(20601);
            this._infoTxt1 = new Object /* flash.text.TextField */();
            this._infoTxt1.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._infoTxt1.width = width;
            this._infoTxt1.height = 18;
            this._infoTxt1.mouseEnabled = false;
            this._infoTxt1.x = 5;
            this._infoTxt1.y = _titleBg2.y + _titleBg2.height + 8;
            this._infoTxt1.htmlText = HTMLUtil.addColor(Language.getString(20612) + HTMLUtil.addColor("：100%", "#00ff00"), GlobalStyle.color1);
            addChild(this._infoTxt1);
            this._infoTxt2 = new Object /* flash.text.TextField */();
            this._infoTxt2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._infoTxt2.width = width;
            this._infoTxt2.height = 18;
            this._infoTxt2.mouseEnabled = false;
            this._infoTxt2.x = this._infoTxt1.x + this._infoTxt1.textWidth + 10;
            this._infoTxt2.y = this._infoTxt1.y;
            this._infoTxt2.htmlText = Language.getString(20613) + "：0";
            addChild(this._infoTxt2);
            this._infoTxt3 = new Object /* flash.text.TextField */();
            this._infoTxt3.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._infoTxt3.width = width;
            this._infoTxt3.height = 18;
            this._infoTxt3.mouseEnabled = false;
            this._infoTxt3.x = this._infoTxt1.x;
            this._infoTxt3.y = this._infoTxt1.y + this._infoTxt1.textHeight + 0;
            this._infoTxt3.htmlText = Language.getStringByParam(20614, "", "");
            addChild(this._infoTxt3);
            this._getTxt1 = new Object /* flash.text.TextField */();
            this._getTxt1.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._getTxt1.width = width;
            this._getTxt1.height = 18;
            this._getTxt1.mouseEnabled = false;
            this._getTxt1.x = this._infoTxt1.x;
            this._getTxt1.y = 98;
            this._getTxt1.htmlText = HTMLUtil.addColor(Language.getString(20608), GlobalStyle.color1);
            addChild(this._getTxt1);
            this._getTxt2 = new Object /* flash.text.TextField */();
            this._getTxt2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._getTxt2.width = width;
            this._getTxt2.height = 18;
            this._getTxt2.mouseEnabled = false;
            this._getTxt2.x = this._getTxt1.x;
            this._getTxt2.y = this._getTxt1.y + this._getTxt1.textHeight + 10;
            this._getTxt2.htmlText = HTMLUtil.addColor(Language.getString(20609), GlobalStyle.color1);
            addChild(this._getTxt2);
            this._getTxt3 = new Object /* flash.text.TextField */();
            this._getTxt3.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._getTxt3.width = width;
            this._getTxt3.height = 18;
            this._getTxt3.mouseEnabled = false;
            this._getTxt3.x = this._getTxt1.x;
            this._getTxt3.y = this._getTxt2.y + this._getTxt2.textHeight + 10;
            this._getTxt3.htmlText = HTMLUtil.addColor(Language.getString(20610), GlobalStyle.color1);
            addChild(this._getTxt3);
            this._getBtn1 = new GButton();
            this._getBtn1.setSize(44, 20);
            this._getBtn1.label = Language.getString(20564);
            this._getBtn1.styleName = "Button";
            this._getBtn1.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtn1ClickHandler);
            this._getBtn1.x = width - this._getBtn1.width - 5;
            this._getBtn1.y = this._getTxt1.y;
            this._getBtn1.textField.filters = [FilterConst.glowFilter];
            addChild(this._getBtn1);
            this._getBtn2 = new GButton();
            this._getBtn2.setSize(44, 20);
            this._getBtn2.label = Language.getString(20564);
            this._getBtn2.styleName = "Button";
            this._getBtn2.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtn2ClickHandler);
            this._getBtn2.x = width - this._getBtn2.width - 5;
            this._getBtn2.y = this._getTxt2.y;
            this._getBtn2.textField.filters = [FilterConst.glowFilter];
            addChild(this._getBtn2);
            this._getBtn3 = new GButton();
            this._getBtn3.setSize(44, 20);
            this._getBtn3.label = Language.getString(20564);
            this._getBtn3.styleName = "Button";
            this._getBtn3.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtn3ClickHandler);
            this._getBtn3.x = width - this._getBtn3.width - 5;
            this._getBtn3.y = this._getTxt3.y;
            this._getBtn3.textField.filters = [FilterConst.glowFilter];
            addChild(this._getBtn3);
            this._numSteper1 = new GNumericStepper();
            this._numSteper1.styleName = "NumericStepper";
            this._numSteper1.setSize(44, 20);
            this._numSteper1.x = 60;
            this._numSteper1.y = this._getTxt1.y;
            this._numSteper1.addEventListener(flash.events.Event.CHANGE, this.onNumSteper1ChangeHandler);
            this._numSteper1.drawNow();
            this._numSteper1.textField.setStyle("upSkin", ResouceConst.getScaleBitmap(ImagesConst.DisabledBg));
            this._numSteper1.textField.drawNow();
            this._numSteper1.minimum = 0;
            this._numSteper1.maximum = 999999;
            addChild(this._numSteper1);
            this._numSteper2 = new GNumericStepper();
            this._numSteper2.styleName = "NumericStepper";
            this._numSteper2.setSize(44, 20);
            this._numSteper2.x = 60;
            this._numSteper2.y = this._getTxt2.y;
            this._numSteper2.addEventListener(flash.events.Event.CHANGE, this.onNumSteper2ChangeHandler);
            this._numSteper2.drawNow();
            this._numSteper2.textField.setStyle("upSkin", ResouceConst.getScaleBitmap(ImagesConst.DisabledBg));
            this._numSteper2.textField.drawNow();
            this._numSteper2.minimum = 0;
            this._numSteper2.maximum = 999999;
            addChild(this._numSteper2);
            this._numSteper3 = new GNumericStepper();
            this._numSteper3.styleName = "NumericStepper";
            this._numSteper3.setSize(44, 20);
            this._numSteper3.x = 60;
            this._numSteper3.y = this._getTxt3.y;
            this._numSteper3.addEventListener(flash.events.Event.CHANGE, this.onNumSteper3ChangeHandler);
            this._numSteper3.drawNow();
            this._numSteper3.textField.setStyle("upSkin", ResouceConst.getScaleBitmap(ImagesConst.DisabledBg));
            this._numSteper3.textField.drawNow();
            this._numSteper3.minimum = 0;
            this._numSteper3.maximum = 999999;
            addChild(this._numSteper3);
            this._countTxt1 = new Object /* flash.text.TextField */();
            this._countTxt1.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._countTxt1.width = width;
            this._countTxt1.height = 18;
            this._countTxt1.mouseEnabled = false;
            this._countTxt1.x = this._numSteper1.x + this._numSteper1.width + 4;
            this._countTxt1.y = this._numSteper1.y;
            this._countTxt1.htmlText = HTMLUtil.addColor(Language.getString(20601), "#00ff00");
            addChild(this._countTxt1);
            this._countTxt2 = new Object /* flash.text.TextField */();
            this._countTxt2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._countTxt2.width = width;
            this._countTxt2.height = 18;
            this._countTxt2.mouseEnabled = false;
            this._countTxt2.x = this._numSteper2.x + this._numSteper2.width + 4;
            this._countTxt2.y = this._numSteper2.y;
            this._countTxt2.htmlText = HTMLUtil.addColor(Language.getString(20601), "#00ff00");
            addChild(this._countTxt2);
            this._countTxt3 = new Object /* flash.text.TextField */();
            this._countTxt3.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._countTxt3.width = width;
            this._countTxt3.height = 18;
            this._countTxt3.mouseEnabled = false;
            this._countTxt3.x = this._numSteper3.x + this._numSteper3.width + 4;
            this._countTxt3.y = this._numSteper3.y;
            this._countTxt3.htmlText = HTMLUtil.addColor(Language.getString(20601), "#00ff00");
            addChild(this._countTxt3);
            this._propCb = new GCheckBox();
            this._propCb.label = Language.getString(20912);
            this._propCb.styleName = "GCheckBox";
            this._propCb.buttonMode = true;
            this._propCb.selected = false;
            this._propCb.width = 200;
            this._propCb.x = 5;
            this._propCb.y = this._countTxt3.y + this._countTxt3.textHeight + 8;
            addChild(this._propCb);
            return;
        }

        /* internal  */get propModule(): OfflineExpPropModule
        {
            if (!this._propModule) 
            {
                this._propModule = new OfflineExpPropModule();
            }
            return this._propModule;
        }

        public updateData(): void
        {
            this._time = Cache.instance.daily.offLineTime;
            this._exp = Cache.instance.daily.offLineExp;
            this._infoTxt2.htmlText = HTMLUtil.addColor(Language.getString(20613) + HTMLUtil.addColor("：" + this._exp, "#ffff00"), GlobalStyle.color1);
            _titleTxt2.htmlText = HTMLUtil.addColor(Language.getString(20600) + "：", GlobalStyle.color2) + HTMLUtil.addColor(this._time + Language.getString(20601), "#00ff00");
            this.updatePackItem();
            return;
        }

        public updatePackItem(): void
        {
            this._itemNum1 = this._time;
            this._itemNum2 = this.getItemNum(200);
            this._itemNum3 = this.getItemNum(300);
            this._itemData1.itemAmount = this._itemNum2;
            this._itemData2.itemAmount = this._itemNum3;
            this._numSteper1.maximum = this._time;
            this._numSteper2.maximum = this._time;
            this._numSteper3.maximum = this._time;
            if (this._time > 0) 
            {
                var loc1;
                this._getBtn3.enabled = loc1 = true;
                this._getBtn2.enabled = loc1 = loc1;
                this._getBtn1.enabled = loc1;
            }
            else 
            {
                this._getBtn3.enabled = loc1 = false;
                this._getBtn2.enabled = loc1 = loc1;
                this._getBtn1.enabled = loc1;
            }
            this._numSteper1.value = this._time;
            this._numSteper2.value = this._time;
            this._numSteper3.value = this._time;
            this._infoTxt3.htmlText = HTMLUtil.addColor(Language.getStringByParam(20614, HTMLUtil.addColor(this._itemData1.itemInfo.item.name, ColorConfig.instance.getItemColor(this._itemData1.color).color) + HTMLUtil.addColor("×" + this._itemNum2, "#ffff00"), HTMLUtil.addColor(this._itemData2.itemInfo.item.name, ColorConfig.instance.getItemColor(this._itemData2.color).color) + HTMLUtil.addColor("×" + this._itemNum3, "#ffff00")), GlobalStyle.color1);
            return;
        }

        /* internal  */getItemNum(arg1: int): int
        {
            return Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(ECategory._ECategoryProp, EProp._EPropOfflineAddExperience, arg1);
        }

        /* internal  */onBuyBtn1ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            QuickBuyWindow.instance.update(this._shopItem1);
            QuickBuyWindow.instance.updateDefaultAmount(this._numSteper2.value);
            QuickBuyWindow.instance.show();
            return;
        }

        /* internal  */onGetBtn1ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._expType = EExpType._EExpTypeDirect;
            if (this._time > 0) 
            {
                this._timeNum = this._numSteper1.value;
                if (this._timeNum > 0) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GetOfflineExp, {"type": _EExpTypeDirect, "time": _timeNum}));
                }
            }
            return;
        }

        /* internal  */onGetBtn2ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._expType = EExpType._EExpTypeTwice;
            if (this._time > 0) 
            {
                this._timeNum = this._numSteper2.value;
                if (this._timeNum > 0) 
                {
                    if (this._timeNum <= this._itemNum2) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GetOfflineExp, {"type": _EExpTypeTwice, "time": _timeNum}));
                    }
                    else if (this._propCb.selected) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GetOfflineExp, {"type": _EExpTypeTwice, "time": _timeNum, "autoBuy": true}));
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(20606));
                        this.propModule.show();
                    }
                }
            }
            return;
        }

        /* internal  */onGetBtn3ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._expType = EExpType._EExpTypeTriple;
            if (this._time > 0) 
            {
                this._timeNum = this._numSteper3.value;
                if (this._timeNum > 0) 
                {
                    if (this._timeNum <= this._itemNum3) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GetOfflineExp, {"type": _EExpTypeTriple, "time": _timeNum}));
                    }
                    else if (this._propCb.selected) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GetOfflineExp, {"type": _EExpTypeTriple, "time": _timeNum, "autoBuy": true}));
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(20606));
                        this.propModule.show();
                    }
                }
            }
            return;
        }

        /* internal  */onItemBuySuccess(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GetOfflineExp, {"type": _expType, "time": _timeNum}));
            return;
        }

        /* internal  */onBuyBtn2ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            QuickBuyWindow.instance.update(this._shopItem2);
            QuickBuyWindow.instance.updateDefaultAmount(this._numSteper3.value);
            QuickBuyWindow.instance.show();
            return;
        }

        /* internal  */onNumSteper1ChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            return;
        }

        /* internal  */onNumSteper2ChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            return;
        }

        /* internal  */onNumSteper3ChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            return;
        }

        /* internal */ /* var */_countTxt3: Object /* flash.text.TextField */;

        /* internal */ /* var */_time: int;

        /* internal */ /* var */_exp: int;

        /* internal */ /* var */_itemNum1: int;

        /* internal */ /* var */_itemNum2: int;

        /* internal */ /* var */_itemNum3: int;

        /* internal */ /* var */_getTxt2: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemData2: ItemData;

        /* internal */ /* var */_shopItem1: ShopItemInfo;

        /* internal */ /* var */_shopItem2: ShopItemInfo;

        /* internal */ /* var */_propModule: OfflineExpPropModule;

        /* internal */ /* var */_propCb: GCheckBox;

        /* internal */ /* var */_infoTxt1: Object /* flash.text.TextField */;

        /* internal */ /* var */_infoTxt2: Object /* flash.text.TextField */;

        /* internal */ /* var */_infoTxt3: Object /* flash.text.TextField */;

        /* internal */ /* var */_getTxt1: Object /* flash.text.TextField */;

        /* internal */ /* var */_expType: int;

        /* internal */ /* var */_getTxt3: Object /* flash.text.TextField */;

        /* internal */ /* var */_getBtn1: GButton;

        /* internal */ /* var */_getBtn2: GButton;

        /* internal */ /* var */_getBtn3: GButton;

        /* internal */ /* var */_numSteper1: GNumericStepper;

        /* internal */ /* var */_itemData1: ItemData;

        /* internal */ /* var */_numSteper2: GNumericStepper;

        /* internal */ /* var */_numSteper3: GNumericStepper;

        /* internal */ /* var */_countTxt1: Object /* flash.text.TextField */;

        /* internal */ /* var */_countTxt2: Object /* flash.text.TextField */;

        /* internal */ /* var */_timeNum: int;
    }
